<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>定时器</title>
</head>
<body>

<script>
    //开启定时器
   /* setInterval(f,1000);*/

    function f(){
        // alert("时间到！");
        console.log("时间到！")
    }
    let count = 0;
    //开启 每2秒执行一次的定时器
    let timer = setInterval(function (){
        console.log("第二种")
        count++;
        if (count==3){
            //停止定时器
            clearInterval(timer)
        }
    },2000);

    //setTimeout(方法,时间间隔) 开启只执行一次的定时器
    setTimeout(f,2000);

</script>
</body>
</html>